//
//  HomeCell.m
//  便签
//
//  Created by  on 2022/9/28.
//

#import "HomeCell.h"
@interface HomeCell()
@property (strong, nonatomic) IBOutlet UIImageView *img;
@property (strong, nonatomic) IBOutlet UILabel *title;
@property (strong, nonatomic) IBOutlet UILabel *subtitle;

@end
@implementation HomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    ///设置阴影，背景颜色不能是透明，否则无效
    self.layer.masksToBounds = NO;
    self.layer.shadowColor = [UIColor colorHex:@"#9B9B9B"].CGColor;
    self.layer.shadowOffset = CGSizeMake(0, 3);
    self.layer.shadowRadius = 12;
    self.layer.cornerRadius = 12;
    self.layer.shadowOpacity = 1;
    CGFloat w = (SCREEN_WIDTH - 20 * 3) / 2;
    CGFloat h = 182 / 153.0 * w;
    CGRect bounds = CGRectMake(0, 0, w, h);
    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = bounds;
    layer.path = path.CGPath;
    self.img.layer.mask = layer;
}

- (void)setModel:(SignModel *)model{
    _model = model;
    self.img.image = [UIImage imageWithData:model.cover];
    self.title.text = LS(model.title);
    dispatch_async(dispatch_get_main_queue(), ^{
       NSString * where = [NSString stringWithFormat:@"where %@=%@ and %@",bg_sqlKey(@"account"),bg_sqlValue(APP.user.account),bg_keyPathValues(@[@"sign.ID",bg_equal,model.ID])];
        NSInteger count = [NoteModel bg_count:nil where:where];
        self.subtitle.text = [NSString stringWithFormat:LS(@"%d篇"),(int)count];
    });
}
- (IBAction)actionForBtn:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
}

@end
